package com.syn.synold4s.control.dialog;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.gaoyi.basemodule.basedialog.BaseFragmentDialog;
import com.syn.synold4s.R;
import com.syn.synold4s.adapter.AlertAdapter;
import com.syn.synold4s.bean.dto.MapAllDeviceDto;
import com.syn.synold4s.databinding.DriverDialogBinding;

public class GoogleMapDriverDialog extends BaseFragmentDialog<DriverDialogBinding> {

    private MapAllDeviceDto data;
    private AlertAdapter alertAdapter;

    public GoogleMapDriverDialog(Context context, MapAllDeviceDto data) {
        super(context);
        this.data = data;
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        mBinding.ivClose.setOnClickListener(view -> dismiss());
        setData();
    }

    private void setData() {
        if (data == null) return;
        alertAdapter = new AlertAdapter(mContext);
        mBinding.rv.setLayoutManager(new LinearLayoutManager(mContext));
        mBinding.rv.setAdapter(alertAdapter);
        mBinding.rv.setItemAnimator(null);
        if (data.getAlertEvents() != null && data.getAlertEvents().size() > 0) {
            mBinding.newDynamicLayout.setVisibility(View.VISIBLE);
            alertAdapter.submitList(data.getAlertEvents());
        }
        mBinding.tvDeviceName.setText(data.getDeviceName());
        if ("SG830-01_offline".equals(data.getIcon())) {
            mBinding.ivDriver.setBackground(getResources().getDrawable(R.drawable.details_offline));
        } else {
            mBinding.ivDriver.setBackground(getResources().getDrawable(R.drawable.details_online));
        }
        mBinding.tvStateName.setText(data.getStateName());
        Drawable mDrawable = ContextCompat.getDrawable(mContext, R.drawable.oval_yellow_bg);
        if (mDrawable != null) {
            mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
        }
        mBinding.tvStateName.setCompoundDrawablesRelative(mDrawable, null, null, null);
        mBinding.tvStateName.setTextColor(getResources().getColor(R.color.color_main));
        mBinding.tvAlertType.setText(getString(R.string.alert_type) + data.getAlarmType());
        mBinding.tvAlertTime.setText(getString(R.string.alert_time) + data.getAlarmTime());
        mBinding.tvAddress.setText(getString(R.string.address_) + data.getAddress());
    }

    @Override
    protected DriverDialogBinding getViewBinding() {
        return DriverDialogBinding.inflate(getLayoutInflater());
    }

    @Override
    protected String getShowTag() {
        return BOTTOM;
    }
}
